
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Mr Bao
 */
public class ViewImage extends Canvas{

    private Image image;

    public ViewImage(byte[] datas) {
        try {
            image = Image.createImage(datas, 0, datas.length);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    protected void paint(Graphics g) {
        int x = 0;
        int y = 0;
        if (image.getWidth() < getWidth()) {
            x = (getWidth() - image.getWidth()) / 2;
        }
        if (image.getHeight() < getHeight()) {
            y = (getHeight() - image.getHeight()) / 2;
        }
        g.drawImage(image, x, y, 0);
    }
}
